package com.atguigu.spzx.manager.service.Impl;

import com.atguigu.spzx.common.log.annotation.Log;
import com.atguigu.spzx.manager.mapper.SysRoleUserMapper;
import com.atguigu.spzx.manager.service.SysRoleUserService;
import com.atguigu.spzx.model.dto.system.AssginRoleDto;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * ClassName: SysRoleUserServiceImpl
 * Package: com.atguigu.spzx.manager.service.Impl
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/2 20:32
 * @Version 1.0
 */
@Service
public class SysRoleUserServiceImpl implements SysRoleUserService {
    @Resource
    private SysRoleUserMapper sysRoleUserMapper;
    /**
     * 添加用户角色关系
     * @param assginRoleDto
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    @Log(title = "SysRole:分配角色",businessType = 1)
    public void doAssign(AssginRoleDto assginRoleDto) {
        //1. 删除该用户已经有的所有角色
        sysRoleUserMapper.deleteRolesByUserId(assginRoleDto.getUserId());
        System.out.println(1/0);
        //2. 添加用户角色关系
        for (Long roleId : assginRoleDto.getRoleIdList()) {
            sysRoleUserMapper.doAssign(roleId,assginRoleDto.getUserId());
        }
    }
}
